﻿// Upgrade NOTE: commented out 'float4 unity_LightmapST', a built-in variable
// Upgrade NOTE: commented out 'sampler2D unity_Lightmap', a built-in variable
// Upgrade NOTE: replaced tex2D unity_Lightmap with UNITY_SAMPLE_TEX2D

Shader "XF/Diffuse/Lightmap" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
	}
	SubShader 
	{
		Tags { "RenderType"="Opaque" }
		
		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#pragma fragmentoption ARB_precision_hint_fastest 
			// #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
			#pragma exclude_renderers d3d11_9x xbox360 ps3 flash

			#include "UnityCG.cginc"

			sampler2D _MainTex;
			float4 _MainTex_ST;
			// sampler2D unity_Lightmap;	
			// float4 unity_LightmapST;

			struct VertexIn
			{
				float4 vertex : POSITION;
				float4 texcoord : TEXCOORD0;
				float4 texcoord1 : TEXCOORD1;
			};

			struct v2f
			{
				half4 pos : SV_POSITION;
				half4 uv : TEXCOORD0;
			};

			v2f vert (VertexIn v) 
			{
				v2f o; 
			
				o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
				o.uv.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
			
				// #ifdef LIGHTMAP_ON
					o.uv.zw = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
				// #endif

				return o; 
			}

			fixed4 frag (v2f IN) : COLOR0 
			{
				fixed4 c = tex2D (_MainTex, IN.uv.xy);
				
				//#ifdef LIGHTMAP_ON
					fixed3 lm = DecodeLightmap (UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.uv.zw));
					c.rgb *= lm.rgb;
				//#endif

				return c;
			}
			ENDCG
		}
	}
	FallBack "Diffuse"
}
